主题
打包NCNN模型为OCR加密包 - OcrEncryptModel
函数简介
将 PP-OCR NCNN 四文件(det/rec 的 .param / .bin)及可选识别字典打成欧拉 OCR 加密包并写入磁盘。
接口名称
OcrEncryptModelDLL 调用
int OcrEncryptModel(long ola, string detParamPath, string detBinPath, string recParamPath, string recBinPath, string dictPath, string password, string savePath);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug 对象指针 |
| detParamPath | 字符串 | 检测模型 .param,如 PP_OCRv5_mobile_det.ncnn.param |
| detBinPath | 字符串 | 检测模型 .bin |
| recParamPath | 字符串 | 识别模型 .param |
| recBinPath | 字符串 | 识别模型 .bin |
| dictPath | 字符串 | 识别字典 UTF-8 文本(一行一字);空 则不写入包内字典 |
| password | 字符串 | 加密密码(UTF-8,不可为空) |
| savePath | 字符串 | 输出加密包路径 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int ret = ola.OcrEncryptModel("C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt");csharp
using OLAPlug;
var ola = new OLAPlugServer();
int ret = ola.OcrEncryptModel("C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt");python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
ret = ola.OcrEncryptModel("C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt")java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
int ret = ola.OcrEncryptModel("C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt");cpp
var ola = com("OlaPlug.OlaSoft")
var ret = ola.OcrEncryptModel("C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt")vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ret = ola.OcrEncryptModel("C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt")text
.局部变量 ola, OLAPlug
ola.创建 ()
ret = ola.OcrEncryptModel(“C:\\test.txt”, “C:\\test.txt”, “C:\\test.txt”, “C:\\test.txt”, “C:\\test.txt”, “value”, “C:\\test.txt”)aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var ret = ola.OcrEncryptModel("C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt");text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
整数 ret = ola.OcrEncryptModel("C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt")cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int32_t ret = ola.OcrEncryptModel("C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt");原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
OcrEncryptModel(instance, "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt");csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int OcrEncryptModel(long ola, string detParamPath, string detBinPath, string recParamPath, string recBinPath, string dictPath, string password, string savePath);
long instance = CreateCOLAPlugInterFace();
OcrEncryptModel(instance, "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt");python
from ctypes import CDLL, c_int, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ola.OcrEncryptModel(instance, "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "C:\\test.txt", "value", "C:\\test.txt")返回值
整数型:1 成功,0 失败。
注意事项
- 产出魔数 OLAOENC1,与 YOLO 包 OLAYENC1 可区分。
dictPath为空为 v1 包(四段模型);非空为 v2 包(四段模型 + 字典)。- 自定义 rec 须与训练时
character_dict/ keys 一致;未打包字典时加载后使用内置ppocrv5_keys。 - Paddle 导出常见字典:
ppocr_keys_v1.txt、dict.txt、key_list.txt(每行一字,index 0 为 CTC blank)。
